/*
 * @Author: 谢子健 1075010289@qq.com
 * @Date: 2024-09-21 23:36:18
 * @LastEditors: 谢子健 1075010289@qq.com
 * @LastEditTime: 2024-10-08 09:58:14
 * @FilePath: \ilink-vue-frontend\src\api\study\course.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { api } from '../api';

// 获取课程信息
export const getCourseInformationById = async (courseId: string) => {
  try {
    const response = await api.get('/java/ground/study/course/get_course_information_by_id', {
      params: { courseId },
    });
    return response.data;
  }
  catch (error) {
    console.error('获取课程信息失败:', error);
    throw error;
  }
};

// 检查是否收藏
export const getFavoriteList = async () => {
  try {
    const response = await api.get('/java/ground/study/course/get_favorite_list');
    return response.data;
  }
  catch (error) {
    console.error('获取收藏信息失败:', error);
    throw error;
  }
};

// 点赞课程
export const likeCourse = async (courseId: string) => {
  try {
    const response = await api.post('/java/ground/study/course/add_course_like', { courseId });
    return response.data;
  }
  catch (error) {
    console.error('点赞请求失败:', error);
    throw error;
  }
};

// 收藏课程
export const addCourseToFavorites = async (courseId: string) => {
  try {
    const response = await api.post('/java/ground/study/course/add_course_collection', { courseId });
    return response.data;
  }
  catch (error) {
    console.error('收藏请求失败:', error);
    throw error;
  }
};

// 获取课程文件目录信息
export const getFolderInfoApi = async (folderId: string) => {
  try {
    const response = await api.get('/java/teacher/StudySpaceTeacher/getAllCourses', { params: { courseFileId: folderId } },
    );
    return response.data;
  }
  catch (error) {
    console.error('获取课程文件目录信息失败', error)
    throw error;
  }
}

// 获取课程具体资源URL，如文件/视频资源/web网页资源等
export const getSourceFileUrlApi = async (sourceId: string) => {
  try {
    const response = await api.get('/java/ground/study/course/get_source_url', {
      params: { sourceId },
    });
    return response.data
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}

// 获取文档资源细节信息，如导读 脑图
export const getDocumentDetailApi = async (sourceId: string) => {
  try {
    const response = await api.get('/java/teacher/StudySpaceTeacher/filecontent', {
      params: { filesource_id: sourceId },
    });
    return response.data
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}

export const getVideoDetailApi = async (sourceId: string) => {
  try {
    const response = await api.get('/java/teacher/StudySpaceTeacher/getSourceTransResult', {
      params: { courseSourceId: sourceId },
    });
    return response.data
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}

export const getPhotoApi = async (objectName: string) => {
  try {
    const response = await api.get('/java/ground/study/course/get_source_url_by_name', {
      params: { objectName },
    });
    return response.data
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}

export const updateCourseStudyRecordApi = async (courseId: string) => {
  try {
    const response = await api.put(`/java/teacher/StudySpaceTeacher/updateCourseFileStudyRecord?courseSourceId=${courseId}`);
    return response.data
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}

export const getSourceNameApi = async (sourceId: string) => {
  try {
    const response = await api.get('/java/ground/study/course/get_source_name', {
      params: { sourceId },
    });
    return response
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}
export const postRetrieveApi = async (query: string, path: string) => {
  try {
    const response = await api.post(`/java/teacher/bailain_index/retrieve?query=${encodeURIComponent(query)}&path=${encodeURIComponent(path)}`);
    return response.data;
  }
  catch (error) {
    console.error('获取资源信息失败', error);
    throw error;
  }
};

export const getCourseFileUrlApi = async (referenceId: string) => {
  try {
    const response = await api.get('/java/StudySpaceStudent/getCourseFileUrl', {
      params: {
        courseSourceId: referenceId,
        SourceType: '文档',
      },
    });
    return response.data
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}

// 获取课程封面HTTP链接
export const getCourseCoverApi = async (ossFilePath: string) => {
  try {
    const response = await api.get('/java/oss/get_fIcon_by_path', {
      params: { path: ossFilePath },
    });
    return response.data
  }
  catch (error) {
    console.error('获取课程封面失败', error)
    throw error
  }
}
